//allchart-chart1 计算速率
$(function () {
    $(document).ready(function () {
        Highcharts.setOptions({
            global: {
                useUTC: false
            }
        });

        var chart;
        $('#allchart-chart1').highcharts({
            chart: {
                type: 'spline',
                backgroundColor: 'rgba(0,0,0,0)',
                animation: Highcharts.svg, // don't animate in old IE               
                marginRight: 10,
                events: {
                    load: function () {

                        // set up the updating of the chart each second             
                        var series = this.series[0];
                        setInterval(function () {
                            $.ajax({
                                url: "/indexManager/engine/speed.do",
                                type: "get",
                                dataType: "json",
                                success: function (result) {
                                    if (result.status == 1) {
                                        var data = result.data;
                                        //alert("shuffleReadRecords"+data.shuffleReadRecords+"executorRunTime"+data.executorRunTime);
                                        series.addPoint([parseInt(data.executorRunTime), parseInt(data.shuffleReadRecords)], true, true);
                                    } else {
                                        alert("没有数据");
                                        series.addPoint([0, 0], true, true);
                                    }
                                }, error: function () {
                                    alert("error")
                                }
                            });
                        }, 3000);
                    }
                }
            },
            title: {
                text: null
            },
            xAxis: {
                type: 'datetime',
                tickPixelInterval: 150,
                labels: {
                    style: {
                        color: '#d3dedf',
                        fontSize: '12px'
                    }
                }
            },
            yAxis: {
                title: {
                    text: '数据条数(千条)',
                    style: {
                        color: '#d3dedf',
                        fontSize: '12px'
                    }
                },
                labels: {
                    style: {
                        color: '#d3dedf',
                        fontSize: '12px'
                    }
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                formatter: function () {
                    return '<b>' + this.series.name + '</b><br/>' +
                        Highcharts.dateFormat('%Y-%m-%d %H:%M:%S', this.x) + '<br/>' +
                        Highcharts.numberFormat(this.y, 5);
                }
            },
            legend: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            credits: {
                enabled: false
            },
            exporting: {
                enabled: false
            },
            series: [{
                name: 'Random data',

                data: (function () {
                    // generate an array of random data                             
                    var data = [],
                        time = (new Date()).getTime(),
                        i;
                    for (i = -19; i <= 0; i++) {
                        data.push({
                            //x: time + i * 1000,
                            //y: Math.random()
                            x: 0,
                            y: 0
                        });
                    }
                    return data;
                })()

            }]
        });
    });

});

//allchart-chart3 内存使用率
$(function () {
    $('#allchart-chart3').highcharts({
        chart: {
            type: 'spline',
            backgroundColor: 'rgba(0,0,0,0)'
        },
        title: {
            text: null
        },
        xAxis: {
            type: 'datetime',
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            }
        },
        yAxis: {
            title: {
                text: '内存数量 (个)',
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            min: 0,
            minorGridLineWidth: 0,
            gridLineWidth: 0,
            alternateGridColor: null
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        plotOptions: {
            spline: {
                lineWidth: 4,
                states: {
                    hover: {
                        lineWidth: 5
                    }
                },
                marker: {
                    enabled: false
                },
                pointInterval: 300000, // one min
                pointStart: Date.UTC(2015, 11, 17, 5, 0, 0)
            }
        },
        series: [{
            name: '0-25%',
            data: [2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 2, 2, 2, 1, 1, 1, 0, 2, 2, 2, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 2, 1, 0, 2, 1, 1, 0, 1, 1, 2, 0, 0, 0, 0, 1,]
        },
            {
                name: '25-50%',
                data: [3, 4, 6, 3, 2, 4, 3, 4, 6, 3, 4, 4, 5, 3, 4, 4, 3, 4, 3, 3, 3, 2, 4, 5, 3, 4, 4, 3, 4, 3, 3, 3, 2, 4, 5, 4, 6, 3, 3, 5, 4, 6, 3, 2, 4, 3, 4, 6, 3, 2, 4, 3, 4, 6, 3, 4, 4, 5, 3, 4, 4, 3, 4, 6, 3, 4, 4, 5, 3,]
            },
            {
                name: '50-75%',
                data: [5, 3, 1, 4, 7, 6, 7, 6, 3, 6, 4, 5, 2, 5, 4, 6, 6, 5, 6, 7, 6, 6, 3, 4, 5, 4, 4, 5, 4, 5, 7, 6, 6, 5, 2, 4, 1, 4, 4, 4, 5, 1, 4, 6, 4, 4, 3, 4, 6, 8, 5, 7, 5, 1, 3, 5, 5, 2, 5, 5, 5, 4, 3, 2, 7, 6, 5, 3, 4,]
            },
            {
                name: '75-100%',
                data: [0, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 2, 0, 1, 1, 1, 0, 1, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0, 1, 2, 1, 1, 0, 1, 2, 2, 0, 1, 1, 1, 0, 1, 2, 2, 0, 0, 0, 1, 0, 1, 2, 2, 0, 1, 1, 1, 0, 1, 2, 2, 0, 0, 0, 1, 2, 2,]
            }
        ]
        ,
        navigation: {
            menuItemStyle: {
                fontSize: '10px'
            }
        }
    });
});


//allchart-chart4 时间GC
$(function () {
    $('#allchart-chart4').highcharts({
        chart: {
            type: 'spline',
            backgroundColor: 'rgba(0,0,0,0)'
        },
        title: {
            text: null
        },
        xAxis: {
            type: 'datetime',
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            }
        },
        yAxis: {
            title: {
                text: 'GC(ms)',
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            min: 0,
            minorGridLineWidth: 0,
            gridLineWidth: 0,
            alternateGridColor: null,
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        plotOptions: {
            spline: {
                lineWidth: 4,
                states: {
                    hover: {
                        lineWidth: 5
                    }
                },
                marker: {
                    enabled: false
                },
                pointInterval: 300000, // one min
                pointStart: Date.UTC(2015, 11, 17, 5, 0, 0)
            }
        },
        series: [
            {
                name: 'action1',
                data: [480, 432, 450, 62, 376, 254, 259, 10, 409, 299, 416, 426, 235, 0, 53, 92, 352, 424, 187, 220, 21, 423, 340, 103, 53, 189, 437, 24, 474, 399, 415, 129, 94, 46, 65, 17, 72, 90, 113, 114, 242, 176, 69, 474, 206, 178, 296, 442, 114, 448,]
            },
            {
                name: 'action2',
                data: [265, 187, 147, 249, 114, 87, 315, 120, 101, 177, 358, 89, 50, 105, 239, 292, 149, 154, 52, 218, 179, 166, 434, 0, 310, 200, 227, 397, 433, 222, 134, 359, 316, 238, 177, 309, 293, 116, 140, 344, 270, 215, 28, 89, 234, 277, 233, 90, 363,]
            },
            {
                name: 'action3',
                data: [118, 169, 11, 9, 335, 498, 498, 412, 278, 45, 209, 135, 484, 154, 57, 133, 340, 228, 286, 493, 56, 53, 479, 234, 283, 0, 490, 169, 292, 279, 449, 111, 349, 418, 4, 2, 393, 32, 380, 192, 105, 292, 243, 394, 418, 102, 371,]
            }
        ]
        ,
        navigation: {
            menuItemStyle: {
                fontSize: '10px'
            }
        }
    });
});


//allchart-chart5 网络传输
$(function () {
    $('#allchart-chart5').highcharts({
        chart: {
            type: 'spline',
            backgroundColor: 'rgba(0,0,0,0)'
        },
        title: {
            text: null
        },
        xAxis: {
            type: 'datetime',
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            }
        },
        yAxis: {
            title: {
                text: 'GC(ms)',
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            labels: {
                style: {
                    color: '#d3dedf',
                    fontSize: '12px'
                }
            },
            min: 0,
            minorGridLineWidth: 0,
            gridLineWidth: 0,
            alternateGridColor: null
        },
        credits: {
            enabled: false
        },
        exporting: {
            enabled: false
        },
        tooltip: {
            valueSuffix: ' 传输速度(MB)'
        },
        plotOptions: {
            spline: {
                lineWidth: 4,
                states: {
                    hover: {
                        lineWidth: 5
                    }
                },
                marker: {
                    enabled: false
                },
                pointInterval: 300000, // one min
                pointStart: Date.UTC(2015, 11, 17, 5, 0, 0)
            }
        },
        series: [
            {
                name: 'shuffle',
                data: [177, 174, 165, 188, 109, 126, 199, 186, 160, 150, 134, 174, 177, 165, 187, 161, 138, 110, 111, 184, 169, 149, 127, 153, 115, 115, 196, 132, 165, 199, 195, 101, 166, 114, 144, 182, 170, 101, 166, 147, 198, 193, 128, 181, 194, 118, 171, 125, 128, 184, 136, 121, 200, 117, 132, 198, 122, 149, 157, 199, 180, 145, 188, 140, 181, 159, 137, 180, 109, 130, 133, 137, 193, 128, 116, 123, 171, 127, 119]
            },
            {
                name: 'blocks',
                data: [186, 177, 122, 191, 149, 127, 113, 185, 179, 177, 167, 129, 170, 158, 197, 104, 152, 106, 134, 105, 123, 111, 172, 102, 105, 152, 169, 200, 140, 145, 115, 158, 122, 171, 175, 118, 104, 145, 195, 198, 170, 118, 176, 175, 152, 196, 182, 164, 130, 174, 149, 190, 167, 175, 187, 191, 148, 108, 113, 173, 177, 157, 177, 187, 137, 173, 118, 132, 101, 107, 165, 159, 161, 158, 170, 194, 174, 126, 185]
            }
        ]
        ,
        navigation: {
            menuItemStyle: {
                fontSize: '10px'
            }
        }
    });
});
